package com.spsoft.vatoutinv.model.dto.vmstransactionflowinvoice;

import com.spsoft.vatoutinv.constants.CommonConstant;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;

/**
 * @author wangy
 * @date 2024/6/20 15:45
 */
@Data
@ApiModel(value = "流水开票-流水拆分")
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class VmsFlowSplitDto {

    @ApiModelProperty(value = "流水开票id", notes = "流水开票id")
    @NotNull(message = "交易流水id不能为空")
    private Long id;

    @ApiModelProperty(value = "流水开票-流水拆分明细", notes = "流水开票-流水拆分明细")
    @NotNull(message = "交易流水拆分信息不能为空")
    private List<VmsFlowSplitItem> item;


    @Data
    @ApiModel(value = "流水开票-流水拆分明细")
    public static class VmsFlowSplitItem {

        @ApiModelProperty(value = "含税金额", notes = "含税金额")
        private BigDecimal hsje;

        @ApiModelProperty(value = "不含税金额", notes = "不含税金额")
        private BigDecimal bhsje;

        @ApiModelProperty(value = "税率", notes = "税率")
        private BigDecimal slv;

        @ApiModelProperty(value = "税额", notes = "税额")
        private BigDecimal se;

        @ApiModelProperty(value = "单价", notes = "单价")
        private BigDecimal dj;

        @ApiModelProperty(value = "数量传1", notes = "数量传1")
        private BigDecimal sl;

        // 计算 不含税金额 * 税率 = 计算税额
        public boolean checkSe() {
            // 计算 不含税金额 * 税率 = 计算税额
            BigDecimal jsse = bhsje.multiply(slv).setScale(2, RoundingMode.HALF_UP);
            // 税额 和 计算税额 的误差可以在 0.01 以内
            return se.subtract(jsse).abs().compareTo(new BigDecimal(CommonConstant.STR_001)) <= 0;
        }

    }


}
